<?php

//$cfg = new Config('access');
$ud = 'etc/uploads/';
$tmpname = tempnam($ud, 'tmp');
if (move_uploaded_file($_FILES['image']['tmp_name'], $tmpname)) {
    error_reporting(E_ALL);
    $file = DataSource::createRecord('file', DataSource::$user);
    $fname = FSTools::fullname($_FILES['image']['name']);
    $fpath = $ud.$file->id();
    FSTools::rename($tmpname, $fpath);
    $file->name = $fname;
    $file->size = filesize($fpath);
    $file->posted = date('Y-m-d H:i:s');
    $file->type = FSTools::mime($fname);
    DataSource::saveRecord($file);
    $return = new TextReturn($file->id());
} else {
    unlink($tmpname);
    header('Content-type: text/html');
    $return = new TextReturn('fail');
}


?>
